@extends('layouts.back_stage')
@section('content')
    <style>
        .info_box{width:100%;height:30px;margin-top:20px;}
        .info_box li{width:25%;float:left;height:30px;}
        .info_box li h3{display: inline;}
        .lining-btn{width:100%;height:40px;margin:30px 0;}
        .lining-btn .lining-a{width:80px;text-align:center;line-height:40px;display:block;background:#00ccff;color:#fff;float:left;margin-left:30px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;}
        .lining-ul{color:#383838; width:80%;height:auto;margin:0 auto;}
        .plan,.reality{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;}
        .plan td,.reality td{text-align:center;height:35px;width: 100px;}
        table,th,td{border:1px solid #ccc;width: 100px;}
        .input{width:100%;height:100%;border:0;outline:none;text-align:center;}
        .saveBtn{float:right;margin-top:30px;}
    </style>
    <div class="container">
        <div>
            <ul class="info_box">
                <li><h3>款号：<span class="getGirard">{{ $plan_info->girard }}</span></h3></li>
                <li><h3>计划单号：{{ $plan_info->plan_code }}</h3></li>
                <li><h3>波段：{{ $plan_info->band_name }}</h3></li>
                <li><h3>品类：{{ $cate[$plan_info->cate_id] }}</h3></li>
            </ul>
            <ul class="info_box">
                <li><h3>投产总量：{{ $plan_info->total }}</h3></li>
                <li><h3>剩余量：{{ $plan_info->total - $plan_info->into_pur }}</h3></li>
                <li><h3>计划加工厂：{{ $plan_info->plan_factory }}</h3></li>
                <li><h3>计划出货日期：2017-10-12</h3></li>
            </ul>
        </div>
        <div class="lining-btn">
            @if(count($info) >0 )
                @foreach($info as $k=>$v)
                    <a class="lining-a" id="l{{ $v->id }}">{{ $v->color }}</a>
                @endforeach
            @endif
        </div>
        <ul class="lining-ul">
            @if(count($info) >0 )
                @foreach($info as $k=>$v)
                    <?php
                    $size = explode(',',rtrim($v->size));
                    $stock = explode(',',rtrim($v->stock));
                    $actual = explode(',',rtrim($v->cut_bed_storage));
                    ?>
                    <li class="lining-li" id="M{{ $v->id }}">
                        <h3>计划</h3>
                        <table class="plan" border="1" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>尺码：</td>
                                @foreach($size as $vs)
                                    <td>{{ $vs }}</td>
                                @endforeach
                            </tr>
                            <tr>
                                <td>计划生产件数：</td>
                                @foreach($stock as $vs)
                                    <td>{{ $vs }}</td>
                                @endforeach
                            </tr>
                        </table>
                        <h3>裁床入库</h3>
                        <table class="reality" border="1" cellspacing="0" cellpadding="0">
                            <tr><td>裁床件数：</td>
                                <?php $i=0;?>
                                @foreach($size as $vs)
                                    <td><input type="text" class="numCount{{ $v->id }} input" value="{{ $actual[$i] or ''}}" placeholder="请输入数量"></td>
                                    <?php $i++;?>
                                @endforeach
                            </tr>
                        </table>
                        <button class="btn btn-primary saveBtn" abc="{{ $v->id }}">保存</button>
                    </li>
                @endforeach
            @endif
        </ul>
    </div>
    <script>
        /*初始化tab切换*/
        $(".lining-a:eq(0)").css("background","#27c24c");
        $(".lining-ul .lining-li").css("display","none");
        $(".lining-ul .lining-li:eq(0)").css("display","block")
        /*点击tab切换*/
        $(".lining-btn").children(".lining-a").click(function(){
            var n=$(this).index();
            $(this).css("background","#27c24c").siblings().css("background","#00ccff");
            $(".lining-ul .lining-li").css("display","none");
            $(".lining-ul .lining-li:eq("+n+")").css("display","block")
        });
        /*保存*/
        $(".saveBtn").click(function(){
            var s = "";
            var id=$(this).attr("abc");
            $('.numCount'+id).each(function () {
                if($(this).val() == ''){
                    s += -999+',';
                }else {
                    s += $(this).val()+',';
                }
            });
            var stock=s.substr(0, s.length - 1);
            console.log(stock);
            if (stock.indexOf("-999") == -1) {
                $.ajax({
                    url:'/storage/cut_bed_save',
                    type:'post',
                    data:{
                        'id':id,
                        'cut_bed_storage':stock,
                        'investment_id':$.getUrlParam('id'),
                        'girard':$('.getGirard').text()
                    },
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    dataType:'json',
                    success:function(data){
                        if(data.success){
                            $(".faceImg").attr("src","/img/laugh.png");
                            $(".oHandle").text("保存成功");
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text("保存失败");
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    }
                })
            } else {
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("实际生产件数不能为空");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        });
        /*实际生产件数*/
        $(".input").bind("input","onpropertychange",function(){
            $(this).val($(this).val().replace(/[^\d]/g,""));
        });
    </script>
@endsection